using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XFGameFramework;
///战斗行为类型
public enum SkillType
{
    //造成伤害
    TakeDamage,
    //治疗
    Heal,
    //赋予效果
    effect,

    //距离效果
    DistanceEffect,

    //逃跑行为
    RunAway,

}

//战斗行为基类
public class  SkillBase 
{   
    public int cooling_rounds;
    public int skillId;
    public int current_cooling_rounds;
    public List<SkillType> skillTypes;
    public RolesModel creator;
    public RolesModel target;

    public virtual void ApplyAction(){ }
}

/// <summary>
/// 造成伤害逻辑
/// </summary> <summary>
/// 
/// </summary>
public class TakeDamageBase : SkillBase
{
    
    Module module = ModuleManager.GetModule("MainModule");
    SkillController skillController => module.LoadController<SkillController>();
    private SkillConfig SkillConfig => XFABManager.AssetBundleManager.LoadAsset<SkillConfig>(module.ModuleName, "SkillConfig");
    public int baseDamage;
    private int damage;

    private PlayerController playerController => module.LoadController<PlayerController>();
    private EnemyController enemyController => module.LoadController<EnemyController>();

 
    //初始化
    public TakeDamageBase(RolesModel creator, RolesModel target,int outskillId)
    {
        
        this.creator = creator;
        this.target = target;
        this.baseDamage = SkillConfig.GetSkillInfo(outskillId).baseDamage;
        this.skillId = outskillId;
        
       
        //skillTypes.Add(SkillType.TakeDamage);
    }

   
    public void ComputeDamage()
    {      
        if (target == null)
        {
            Debug.LogError("target is null");
            return;
        }       
        //伤害计算
        int finalDamage = CalculateDamage(baseDamage,target);
        //扣除生命值
        if (target is PlayerModel)
        {
            playerController.CurrentHp -= finalDamage;
        }
        else if (target is EnemyModel)
        {
            enemyController.CurrentHp -= finalDamage;
        }
        Debug.LogFormat("{0} 对 {1} 造成了 {2} 点伤害",creator.name, target.name, finalDamage);
    }
    public virtual int CalculateDamage(int baseDamage, RolesModel target)
    {
        return baseDamage;
    }

}
/// <summary>
/// 赋予治疗逻辑    
/// </summary> 
public class TakeHealBase : SkillBase
{
    Module module = ModuleManager.GetModule("MainModule");
    private SkillConfig SkillConfig => XFABManager.AssetBundleManager.LoadAsset<SkillConfig>(module.ModuleName, "SkillConfig");
        public int baseHeal;

    private PlayerController playerController => module.LoadController<PlayerController>();

    public TakeHealBase(RolesModel creator, RolesModel target, int outskillId    )
 {      
        this.skillId = outskillId;
        this.creator = creator;
        this.target = target;
        this.baseHeal = SkillConfig.GetSkillInfo(outskillId).baseHeal;
    }
    //ApplyAction
    public void TaekHeal()
    {

        if (target == null)
        {
            Debug.LogError("target is null");
            return;
        }

        //治疗计算
        int finalHeal = CalculateHeal();
        //治疗生命值
        target.currentHp += finalHeal;  

    }
    
    public virtual int CalculateHeal( )
    {
        int finalHeal = baseHeal;

        //治疗计算逻辑

        return finalHeal;
    }
}
/// <summary>
/// 赋予效果逻辑
/// </summary> 
public class SetEffectBase : SkillBase
{


}

/// <summary>
/// 赋予距离效果
/// </summary> 
public class DistanceBase : SkillBase
{

}
